<?php
/**
* @version $Id: Heriniaina Eugene  04/05/2006 17.23 $
* @package mod_annibalquotes
* @copyright Copyright (C) 2006 serasera.org
* @comment This module shows daily quotes from Annibale Difrancia
*/

// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

$option = trim( mosGetParam( $_REQUEST, 'option', null ) );
$task = trim( mosGetParam( $_REQUEST, 'task', null ) );
$id = intval( mosGetParam( $_REQUEST, 'id', null ) );

global $mosConfig_cachepath;


// use cache if available

require_once( $mosConfig_absolute_path . '/includes/Cache/Lite.php' );

$nullDate 			= $database->getNullDate();
$noauth 			= !$mainframe->getCfg( 'shownoauth' );
$nbx_sectionid =  intval($params->def('nbx_sectionid', 0));
$nbx_rows =  intval($params->def('nbx_rows', 2));
$nbx_columns =  intval($params->def('nbx_columns', 1));
$nbx_showtitles =  intval($params->def('nbx_showtitles', 1));
$nbx_showintro =  intval($params->def('nbx_showintro', 1));
$nbx_introlength =  intval($params->def('nbx_introlength', 300));
$nbx_introformat =  $params->def('nbx_introformat', 'Text');
$nbx_readmore =  intval($params->def('nbx_readmore', 1));

if($nbx_sectionid > 0) {


	$query = "SELECT a.id, a.introtext, a.images, a.fulltext, a.attribs, a.title, a.state"
	."\n FROM #__content AS a"
	."\n INNER JOIN #__categories AS cc ON cc.id = a.catid"
	."\n INNER JOIN #__sections AS s ON s.id = a.sectionid"
	."\n WHERE a.state = 1"
	. ( $noauth ? "\n AND a.access <= " . (int) $my->gid . " AND cc.access <= " . (int) $my->gid . " AND s.access <= " . (int) $my->gid : '' )
	."\n AND (a.publish_up = " . $database->Quote( $nullDate ) . " OR a.publish_up <= " . $database->Quote( $now ) . " ) "
	."\n AND (a.publish_down = " . $database->Quote( $nullDate ) . " OR a.publish_down >= " . $database->Quote( $now ) . " )"
	."\n AND a.sectionid = " . (int) $nbx_sectionid
	."\n AND cc.published = 1"
	."\n AND s.published = 1"
	."\n ORDER BY a.ordering "
	;

	$database->setQuery( $query, 0, $nbx_rows );
	if($rows = $database->loadObjectList()) {
		echo "<div class=\"" . $params->get( 'moduleclass_sfx') . "box\">";
		echo ($nbx_columns > 1) ? "<table><tr><td valign=\"top\">" : "";
		
		$col = 0;
		foreach($rows as $row) {
			$col++;
			echo ($nbx_showtitles != 0) ? "<div class=\"title\">" . $row->title . "</div>": "";
			if($nbx_showintro != 0) {
				echo "<div class=\"text\">";
				if($nbx_introformat == 'Text') {
					if($nbx_introlength > 0) {
						echo substr(strip_tags($row->introtext), 0, $nbx_introlength);
					} else {
						echo strip_tags($row->introtext);
					}
				} else {
					echo ampReplace( $row->introtext );
				}
				echo "</div>";
			}
			echo ($nbx_readmore != 0 ) ? "<div class=\"readmore\"><a href=\"" . sefRelToAbs( 'index.php?option=com_content&amp;task=view&amp;id=' . $row->id . $row->Itemid_link ) . "\" class=\"readon" . $params->get( 'moduleclass_sfx') . "\">" . _READ_MORE . "</a></div>": "";
			echo ($nbx_columns > 1 && ( $nbx_columns % $col == 0)) ? "</td><td valign=\"top\">" : "";
		}
		echo ($nbx_columns > 1) ? "</td></tr></table>" : "";

		echo "</div>";
	}

	
} else {
	echo "This module is not yet configured... Please configure it or remove it.";
}
?>